package com.hldsmart.smartda.activity.mine;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.TextView;

import com.hldsmart.smartda.R;
import com.hldsmart.smartda.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MyGroupActivity extends BaseActivity implements View.OnClickListener {

    @Bind(R.id.iv_mygroup_back)
    ImageView iv_mygroup_back;

    private List<View> listViews;
    private ImageView cursorIv;
    private TextView tab01, tab02, tab03;
    private TextView[] titles;
    private ViewPager viewPager;

    /**
     * 偏移量（手机屏幕宽度 / 选项卡总数 - 选项卡长度） / 2
     */
    private int offset = 0;

    /**
     * 下划线图片宽度
     */
    private int lineWidth;

    /**
     * 当前选项卡的位置
     */
    private int current_index = 0;

    /**
     * 选项卡总数
     */
    private static final int TAB_COUNT = 3;

    private static final int TAB_0 = 0;

    private static final int TAB_1 = 1;

    private static final int TAB_2 = 2;


    public static void startMyGroupActivity(Context context) {
        Intent intent = new Intent(context, MyGroupActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_group);
        ButterKnife.bind(this);


        initUI();
        initImageView();
        setListener();
    }

    private void setListener() {
        iv_mygroup_back.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_mygroup_back:
                finish();
                break;

            case R.id.tv01:
                // 避免重复加载
                tab01.setTextColor(Color.rgb(30,189,255));
                break;
            case R.id.tv02:
                tab02.setTextColor(Color.rgb(30,189,255));

                break;
            case R.id.tv03:
                tab03.setTextColor(Color.rgb(30,189,255));
                break;
        }
    }

    /**
     * 初始化布局和监听
     */
    private void initUI() {
        cursorIv = (ImageView) findViewById(R.id.iv_tab_bottom_img);
        tab01 = (TextView) findViewById(R.id.tv01);
        tab02 = (TextView) findViewById(R.id.tv02);
        tab03 = (TextView) findViewById(R.id.tv03);

        tab01.setOnClickListener(this);
        tab02.setOnClickListener(this);
        tab03.setOnClickListener(this);

    }

    /**
     * 初始化底部下划线
     */
    private void initImageView() {
        // 获取图片宽度
        lineWidth = BitmapFactory.decodeResource(getResources(), R.drawable.ic_bule_line).getWidth();
        // Android提供的DisplayMetrics可以很方便的获取屏幕分辨率
        DisplayMetrics dm = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenW = dm.widthPixels; // 获取分辨率宽度
        offset = (screenW / TAB_COUNT - lineWidth) / 2;  // 计算偏移值
        Matrix matrix = new Matrix();
        matrix.postTranslate(offset, 0);
        // 设置下划线初始位置
        cursorIv.setImageMatrix(matrix);
    }

}
